home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / s342q08.lha / confg2.c < prev    next >
C/C++ Source or Header  |  1994-09-21  |  10KB  |  410 lines

  1. /*
  2. *       confg2.c
  3. *
  4. * Event configuration program for Citadel bulletin board system.
  5. */
  6. #define CONFIGURE
  7. #include "ctdl.h"
  8. /*
  9. *       History
  10. *
  11. * 87Oct02 HAW  Created.
  12. */
  13. /*
  14. *       Contents
  15. *
  16. * checkList()   searches for a given string
  17. * EatEvent()    Digests a #event
  18. * FigureNets()    eats a comma separated list of nets
  19. * getLVal()   gets a field value from a #event line
  20. */
  21. int EvWCt    = 0;
  22. #define PARA1 "\nWARNING: An event of Class dl-time should only use type quiet\n"
  23. #define PARA2 "\nWARNING: An event of Class anytime-net should only use type quiet\n"
  24. #define PARA3 "\nWARNING: Events of Class chat-on and chat-off should only use type quiet\n"
  25. #define PARA4 "\nWARNING: Events of Class newusers-allowed and newusers-disallowed should only use type quiet\n"
  26. #define PARA5 "Events of Class until-done-net cannot be of type quiet.\n"
  27. #define PARA6 "Events of Class netcache cannot be of type quiet.\n"
  28. typedef struct
  29.   {
  30.   char *GenName;
  31.   int  GenVal;
  32.  
  33.   }
  34. GenList;
  35.  
  36.   /***  INDENT-OFF ***/
  37.  
  38.  
  39. static GenList EvnDays[] =
  40.   {
  41.     {    "Sun", SUNDAYS     },
  42.     {    "Mon", MONDAYS     },
  43.     {    "Tue", TUESDAYS    },
  44.     {    "Wed", WEDNESDAYS  },
  45.     {    "Thu", THURSDAYS   },
  46.     {    "Fri", FRIDAYS     },
  47.     {    "Sat", SATURDAYS   },
  48.     {    "All", ALL_DAYS    }
  49.   };
  50.  
  51. static GenList EvnTypes[] =
  52.   {
  53.     {    "preempt",     TYPREEMPT  },
  54.     {    "non-preempt", TYNON      },
  55.     {    "quiet",       TYQUIET    }
  56.   };
  57.  
  58.  
  59. static GenList EvCls[] =
  60.   {
  61.     {    "network",             CLNET        },
  62.     {    "external",            CLEXTERN     },
  63.     {    "relative",            CLREL        },
  64.     {    "dl-time",             CL_DL_TIME   },
  65.     {    "anytime-net",         CL_ANYTIME_NET   },
  66.     {    "door-limit",          CL_DOOR_TIME },
  67.     {    "autodoor",            CL_AUTODOOR  },
  68.     {    "chat-on",             CL_CHAT_ON   },
  69.     {    "chat-off",            CL_CHAT_OFF  },
  70.     {    "redirect",            CL_REDIRECT  },
  71.     {    "newusers-allowed",    CL_NEWUSERS_ALLOWED   },
  72.     {    "newusers-disallowed", CL_NEWUSERS_DISALLOWED   },
  73.     {    "until-done-net",      CL_UNTIL_NET  },
  74.     {    "netcache",            CL_NETCACHE   },
  75.     };
  76.   SListBase Events ={
  77.   NULL, NULL, NULL, EvFree, NULL
  78.  
  79.   };
  80.    /**  INDENT-ON **/
  81. extern CONFIG cfg;      /* The configuration variable   */
  82. extern EVENT  *EventTab;
  83. typedef struct
  84.   {
  85.   EVENT *Evt;
  86.   char  doorname[10];     /* inefficient?  who cares...   */
  87.  
  88.   }
  89. DLK;
  90. int checkList(char *ptr, GenList listing[], int elements);
  91. /*
  92. * EatEvent()
  93. *
  94. * This function assimilates event parameters.  Format:
  95. *
  96. *    #event <days> <time> <class> <type> <duration> <warning string> <dep>
  97. */
  98. int EatEvent(char *line, int offset)
  99.   {
  100.   EVENT *EvBuf;
  101.   DLK   *DataLk;
  102.   char  *ptr, temp[10];
  103.   int   rover, i, Day;
  104.   int   EvHour, EvMin;
  105.   EvBuf = (EVENT *) GetDynamic(sizeof *EvBuf);
  106.   if ((ptr = strchr(line, '\n')) != NULL)
  107.   *ptr = 0;
  108.   rover   = 6;  /* starting index into line '#event ' ... */
  109.   Day     = FigureDays(getLVal(line, &rover, ' '));
  110.   EvHour    = atoi(getLVal(line, &rover, ':'));
  111.   EvMin   = atoi(getLVal(line, &rover, ' '));
  112.   EvBuf->EvMinutes  = EvHour * 60 + EvMin;
  113.   ptr     = getLVal(line, &rover, ' ');
  114.   EvBuf->EvClass  = checkList(ptr, EvCls, NumElems(EvCls));
  115.   if (EvBuf->EvClass != CLREL)
  116.     {
  117.     if (EvHour > 23 || EvMin > 59)
  118.     illegal("Bad time specified for an event!\n");
  119.     EvBuf->EvMinutes = EvHour * 60 + EvMin;
  120.  
  121.     }
  122.   ptr     = getLVal(line, &rover, ' ');
  123.   EvBuf->EvType = checkList(ptr, EvnTypes, NumElems(EvnTypes));
  124.   EvBuf->EvDur  = atoi(getLVal(line, &rover, ' '));
  125.   if( EvBuf->EvDur < 1)
  126.     {
  127.     printf("Warning, duration is less than 1 minute\n");
  128.     };
  129.   EvBuf->EvWarn = GetStoreQuote(line, cfg.codeBuf, &rover, &offset);
  130.   switch (EvBuf->EvClass)
  131.     {
  132.     case CL_ANYTIME_NET:
  133.     EvBuf->vars.Anytime.EvDeadTime = atoi(getLVal(line, &rover, ' ')) * 60l;
  134.     EvBuf->vars.Anytime.EvAnyDur   = atoi(getLVal(line, &rover, ' '));
  135.     if (EvBuf->vars.Anytime.EvDeadTime < 5 )
  136.       {
  137.       printf(" Warning, Anytime-net event has deadtime(%ld) less than 5 minutes\n",EvBuf->vars.Anytime.EvDeadTime);
  138.       };
  139.     if (EvBuf->vars.Anytime.EvAnyDur < 1 )
  140.       {
  141.       printf(" Warning, Anytime-net event has duration(%d) less than 1 minutes\n",EvBuf->vars.Anytime.EvAnyDur);
  142.       };
  143.     /* no break */
  144.     case CLNET:
  145.     case CL_UNTIL_NET:
  146.     EvBuf->EvExitVal = FigureNets(getLVal(line, &rover, ' '));
  147.     if (EvBuf->EvClass == CL_ANYTIME_NET && EvBuf->EvType != TYQUIET)
  148.       {
  149.       printf(PARA2);
  150.       EvBuf->EvType = TYQUIET;
  151.  
  152.       }
  153.     if (EvBuf->EvClass == CL_UNTIL_NET && EvBuf->EvType == TYQUIET)
  154.       {
  155.       illegal(PARA5);
  156.  
  157.       }
  158.     break;
  159.     case CL_NETCACHE:
  160.     if (EvBuf->EvType == TYQUIET)
  161.       {
  162.       illegal(PARA6);
  163.  
  164.       }
  165.     EvBuf->EvExitVal = FigureNets(getLVal(line, &rover, ' '));
  166.     break;
  167.     case CL_AUTODOOR:
  168.     i = 0;
  169.     GetStoreQuote(line, EvBuf->vars.EvUserName, &rover, &i);
  170.     strCpy(temp, getLVal(line, &rover, ' '));
  171.     break;
  172.     case CL_CHAT_ON:
  173.     case CL_CHAT_OFF:
  174.     if (EvBuf->EvType != TYQUIET)
  175.       {
  176.       printf(PARA3);
  177.       EvBuf->EvType = TYQUIET;
  178.  
  179.       }
  180.     break;
  181.     case CL_NEWUSERS_ALLOWED:
  182.     case CL_NEWUSERS_DISALLOWED:
  183.     if (EvBuf->EvType != TYQUIET)
  184.       {
  185.       printf(PARA4);
  186.       EvBuf->EvType = TYQUIET;
  187.  
  188.       }
  189.     break;
  190.     case CL_REDIRECT: /* filename targetdir systemname */
  191.     strCpy(EvBuf->vars.Redirect.EvFilename, getLVal(line, &rover, ' '));
  192.     EvBuf->vars.Redirect.EvHomeDir = offset;
  193.     strCpy(cfg.codeBuf + offset, getLVal(line, &rover, ' '));
  194.     while (cfg.codeBuf[offset++])
  195.     ;
  196.     strCpy(EvBuf->vars.Redirect.EvSystem, line + rover + 1);
  197.     break;
  198.     case CLREL:
  199.     case CLEXTERN:
  200.     case CL_DL_TIME:
  201.     case CL_DOOR_TIME:
  202.     EvBuf->EvExitVal = (MULTI_NET_DATA) atoi(getLVal(line, &rover, ' '));
  203.     if (EvBuf->EvType != TYQUIET && EvBuf->EvClass == CL_DL_TIME)
  204.       {
  205.       printf(PARA1);
  206.       EvBuf->EvType = TYQUIET;
  207.  
  208.       }
  209.     if (EvBuf->EvClass != CL_DL_TIME &&
  210.     EvBuf->EvClass != CL_DOOR_TIME)
  211.       {
  212.       if (EvBuf->EvExitVal >=0 && EvBuf->EvExitVal < 5)
  213.       printf("\n\007WARNING: Event ERRORLEVEL value is "
  214.       "between 0 and 4, all of which are used by "
  215.       "Citadel.\007\n");
  216.  
  217.       }
  218.     break;
  219.  
  220.     }
  221.   /* now check to see which days this event is active */
  222.   if (EvBuf->EvClass != CLREL)
  223.     {
  224.     for (rover = 0, i = 1; rover < 7; EvBuf->EvMinutes += 1440, rover++)
  225.       {
  226.       if (Day & i)
  227.         {
  228.         DataLk = (DLK *) GetDynamic(sizeof *DataLk);
  229.         DataLk->Evt = (EVENT *) GetDynamic(sizeof *EvBuf);
  230.         memcpy(DataLk->Evt, EvBuf, sizeof *EvBuf);
  231.         strCpy(DataLk->doorname, temp);
  232.         AddData(&Events, DataLk, NULL, FALSE);
  233.         cfg.EvNumber++;
  234.  
  235.         }
  236.       i = i << 1;
  237.  
  238.       }
  239.  
  240.     }
  241.   else
  242.     {
  243.     EvBuf->EvDur = EvHour * 60 + EvMin;
  244.     DataLk = (DLK *) GetDynamic(sizeof *DataLk);
  245.     DataLk->Evt = (EVENT *) GetDynamic(sizeof *EvBuf);
  246.     memcpy(DataLk->Evt, EvBuf, sizeof *EvBuf);
  247.     AddData(&Events, DataLk, NULL, FALSE);
  248.     cfg.EvNumber++;
  249.  
  250.     }
  251.   return offset;
  252.  
  253.   }
  254. /*
  255. * checkList()
  256. *
  257. * This function searches for a given string in a list of arrays.  This is
  258. * used for both classes and types.
  259. */
  260. int checkList(char *ptr, GenList listing[], int elements)
  261.   {
  262.   int rover;
  263.   char message[100];
  264.   for (rover = 0; rover < elements; rover++)
  265.   if (strCmpU(ptr, listing[rover].GenName) == SAMESTRING)
  266.   return listing[rover].GenVal;
  267.   sPrintf(message, "'%s' is not recognized!\n", ptr);
  268.   illegal(message);
  269.   return ERROR;
  270.  
  271.   }
  272. /*
  273. * getLVal()
  274. *
  275. * This function gets a field value from a #event line.
  276. */
  277. char *getLVal(char *line, int *rover, char fin)
  278.   {
  279.   static char retVal[75];
  280.   int         i;
  281.   if (!line[*rover])
  282.     {
  283.     retVal[0] = 0;
  284.     return retVal;
  285.  
  286.     }
  287.   if (line[*rover] != '\n')
  288.   (*rover)++;
  289.   while (line[*rover] == ' ') (*rover)++;
  290.   i = 0;
  291.   while (line[*rover] != fin && line[*rover] != '\n' &&
  292.   line[*rover] != 0       )
  293.     {
  294.     retVal[i++] = line[*rover];
  295.     (*rover)++;
  296.  
  297.     }
  298.   retVal[i] = 0;
  299.   return retVal;
  300.  
  301.   }
  302. /*
  303. * FigureNets()
  304. *
  305. * This function takes a comma separated list of nets and eats it.
  306. */
  307. MULTI_NET_DATA FigureNets(char *str)
  308.   {
  309.   MULTI_NET_DATA retVal, r;
  310.   int temp;
  311.   retVal = 0l;
  312.   while (*str)
  313.     {
  314.     temp = atoi(str);
  315.     if (temp < 1 || temp > 31) illegal("Bad member net value (0 < x < 32");
  316.     r = 1l;
  317.     retVal = retVal + (r << (temp - 1));
  318.     while (*str != ',' && *str) str++;
  319.     if (*str) str++;
  320.  
  321.     }
  322.   return retVal;
  323.  
  324.   }
  325. /*
  326. * GetStoreQuote()
  327. *
  328. * This function reads in a quoted string and stores it in codeBuf.
  329. */
  330. int GetStoreQuote(char *line, char *target, int *rover, int *offset)
  331.   {
  332.   int OldOffset;
  333.   OldOffset = *offset;
  334.   while (line[*rover] == ' ') (*rover)++;
  335.   if (line[*rover] != '\"')
  336.   illegal("Expecting a quote mark in event processor!\n");
  337.   (*rover)++;
  338.   if (line[*rover] == '\"')
  339.     {
  340.     (*rover)++;
  341.     return ERROR;
  342.  
  343.     }
  344.   while (line[*rover] != '\"' && line[*rover] != '\r')
  345.     {
  346.     target[(*offset)++] = line[*rover];
  347.     (*rover)++;
  348.  
  349.     }
  350.   target[(*offset)++] = 0;
  351.   (*rover)++;
  352.   return OldOffset;
  353.  
  354.   }
  355. /*
  356. * FigureDays()
  357. *
  358. * This function reads and interprets the <days> field.
  359. */
  360. int FigureDays(char *vals)
  361.   {
  362.   int results, rover;
  363.   char val[4];
  364.   results = 0;
  365.   while (*vals)
  366.     {
  367.     for (rover = 0; rover < 3; rover++)
  368.     val[rover] = *vals++;
  369.     val[3] = 0;
  370.     results += checkList(val, EvnDays, NumElems(EvnDays));
  371.     if (*vals) vals++;      /* bypass ',' */
  372.  
  373.     }
  374.   return results;
  375.  
  376.   }
  377. /*
  378. * EvIsDoor()
  379. *
  380. * This function is used by RunList, etc.  It does final init on #events
  381. * which control autodoors.
  382. */
  383. void EvIsDoor(DLK *d)
  384.   {
  385.   if (d->Evt->EvClass == CL_AUTODOOR)
  386.   d->Evt->EvExitVal = (MULTI_NET_DATA) FindDoorSlot(d->doorname);
  387.  
  388.   }
  389. /*
  390. * EvFree()
  391. *
  392. * This function frees part of a list of events.  Superfluous????
  393. */
  394. void EvFree(DLK *d)
  395.   {
  396.   free(d->Evt);
  397.   free(d);
  398.  
  399.   }
  400. /*
  401. * EventWrite()
  402. *
  403. * This function moves the element to the designated array position.
  404. */
  405. void EventWrite(DLK *d)
  406.   {
  407.   memcpy(EventTab + EvWCt++, d->Evt, sizeof (EVENT));
  408.  
  409.   }
  410.